package com.example.tao.mycar;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.avos.avoscloud.AVAnalytics;
import com.avos.avoscloud.AVUser;
import com.example.tao.mycar.activity.HomeActivity;
import com.example.tao.mycar.database.OperateDBUtils;
import com.example.tao.mycar.login.LoginActivity;

public class MainActivity extends MyActionBarActivity {

    private LinearLayout imageView;

    private OperateDBUtils mOperateDBUtils;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MyApplication.getInstance().addActivity(this);
        imageView = (LinearLayout)this.findViewById(R.id.imageView);

        AVAnalytics.trackAppOpened(getIntent());

        mOperateDBUtils = new OperateDBUtils(this);
        if (AVUser.getCurrentUser() != null) {
            mOperateDBUtils.queryUserHeightData();
            mOperateDBUtils.queryUserWeightData();
        }

        if (!MyApplication.DEBUG) {

        }
        imageView.setVisibility(View.VISIBLE);
        Message message = new Message();
        message.what = 0x01;
        mHandler.sendMessageDelayed(message, 2000);
    }

    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0x01:
                    if (AVUser.getCurrentUser() != null) {
                        Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                        startActivity(intent);
                    } else {
                        Intent intent = new Intent(MainActivity.this, LoginActivity.class);
                        startActivity(intent);
                    }

                    break;
                default:
                    break;
            }
        }
    };

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
